<?php
/**
 * Created by PhpStorm.
 * User: lenvo
 * Date: 2018/6/24
 * Time: 19:58
 */

namespace app\merchant\model;


use think\Db;
use think\Model;

class MerMenu extends Model{
    public function get_auth_menu($mer_id){
        $records = $this->alias("mm")
            ->field("mm.*")
            ->join("MerAuthRecord mar","mar.menu_id = mm.id","LEFT")
            ->join("MerAuthAso maa","maa.auth_id = mar.auth_id","LEFT")
            ->where("mm.option","menu")
            ->where("status",1)
            ->where("maa.mer_id",$mer_id)
            ->select();
        if($records) {
            return $records;
        }else {
            return false;
        }
    }

    public function get_auth_button($mer_id,$rule_value){
        $menu = $this->where("rule_value",$rule_value)->find();
        $records = $this->alias("mm")
            ->join("MerAuthRecord mar","mar.menu_id = mm.id","LEFT")
            ->join("MerAuthAso maa","maa.auth_id = mar.auth_id","LEFT")
            ->where("mm.option","button")
            ->where("status",1)
            ->where("mm.pid",$menu['id'])
            ->where("maa.mer_id",$mer_id)
            ->select();

        return $records;

    }

}